package com.jinkaimen.kqb.ui.holder;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ht.baselibs.ui.base.BaseViewHolder;
import com.jinkaimen.kqb.R;
import com.jinkaimen.kqb.bean.hss.PaymentMethodBean;

import java.math.BigDecimal;

public class PayMethodHolder extends BaseViewHolder<PaymentMethodBean> {
    private TextView mTvItemChannelName;
    private ImageView mIvItemPayMethod;
    private TextView mTvItemSettleType;
    private TextView mTvItemChannelRateAndFee;
    private TextView mTvItemLimitAmount;

    public PayMethodHolder() {
        super(R.layout.list_item_view_select_paument_method);
    }

    @Override
    protected void initView() {
        mTvItemChannelName = findViewById(R.id.tv_item_channel_name);
        mIvItemPayMethod = findViewById(R.id.iv_item_pay_method);
        mTvItemSettleType = findViewById(R.id.tv_item_settle_type);
        mTvItemChannelRateAndFee = findViewById(R.id.tv_item_channel_rate_and_fee);
        mTvItemLimitAmount = findViewById(R.id.tv_item_limit_amount);

    }

    @Override
    protected void refreshView(PaymentMethodBean paymentMethodBean) {
        mTvItemChannelName.setText(paymentMethodBean.channelName);
        mIvItemPayMethod.setVisibility(paymentMethodBean.recommend == 1 ? View.VISIBLE : View.GONE);
        mTvItemSettleType.setText(paymentMethodBean.settleType);
        String channelRate = new BigDecimal(paymentMethodBean.channelRate).multiply(new BigDecimal("100")) + "";
        mTvItemChannelRateAndFee.setText(getTwoNum(channelRate) + "％ + " + getOneNum(paymentMethodBean.channelFee));
        mTvItemLimitAmount.setText(paymentMethodBean.limitAmount);
    }

    private String getTwoNum(String num) {

        if (!TextUtils.isEmpty(num) && num.length() > 4) {
            num = num.substring(0, 4);
        }
        return num;

    }

    private String getOneNum(String num) {

        if (!TextUtils.isEmpty(num) && num.length() > 1) {
            num = num.substring(0, 1);
        }
        return num;

    }

}
